(function(){
    var Report_List_cache = {};
    var Report_List_href = '';
    var Report_List = {

        init: function() {
            var that = this;

            $.ajax({
                url: COMMONURL + 'api/Account/GetSendMeum',
                dataType: 'jsonp',
                jsonp: 'jsonpcallback',
                data: {
                    type: 4,
                    token: $.cookie('token')
                }
            }).done(function(data) {
                var menu = data.menu;
                var compiled = _.template($("#Report_List_nav").html());
                var compiled_cont = _.template($("#Report_List_cont").html());

                $("#fiHeader").html(compiled(menu));
                $("#myTabContent").html(compiled_cont(menu));

                that.firstaction();
                that.shownaction();


            });
        },
        shownaction: function() {
            $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
                // alert(e.target.href) // newly activated tab
                var idname = $(e.target).attr('href').replace('#', '');
                var index = $('a[data-toggle="tab"]').index($(e.target))

                $.cookie('Report_List_index', idname);
                $.cookie('Report_List_point', index);

                if (Report_List_cache[idname]) {
                    $('#' + idname).html(Report_List_cache[idname]);
                    $("#addItem").hide();
                } else {
                    $.ajax({
                        url: idname + '.html'
                    }).done(function(data) {
                        Report_List_cache[idname] = data;
                        $('#' + idname).html(data);

                        $("#addItem").hide();
                    })
                }
            })
        },
        firstaction: function() {
            var firstName = $('a[data-toggle="tab"]').eq(0).attr('href').replace('#', '');
            var point = location.hash.replace('#','').split("&")[1];
            if ($.cookie('Report_List_point') != 0 && $.cookie('Report_List_point')) {
                if (!!$.cookie('Report_List_index')) {
                    firstName = $.cookie('Report_List_index');
                    $('a[href="#' + firstName + '"]').tab('show');
                    return;
                }
            } else {
                if ($.cookie('Report_List_index') && firstName != $.cookie('Report_List_index')) {
                    firstName = $.cookie('Report_List_index');
                    $('a[href="#' + firstName + '"]').tab('show');

                } else {

                    if (Report_List_cache[firstName]) {

                        $('#' + firstName).html(Report_List_cache[firstName]);
                    } else {
                        $.ajax({
                            url: firstName + '.html'
                        }).done(function(data) {
                            Report_List_cache[firstName] = data;
                            $('#' + firstName).html(data);

                        })
                    }
                }

            }
        }
    }
    Report_List.init();
}());